/*

01c_email_survey.do
(this do file is called from 01_make_data.do)

Purpose: clean the email survey data
Inputs: email_survey2019_clean, email-survey2020-clean
Outputs: email_survey
	
*/

// (parentid level dataset)

foreach year in 2019 2020 {

	insheet using "${email_survey`year'}", clear
	
	// Only consider completed surveys
	
	keep if finished == "True"
	gen year = `year'
	
	keep q* parentid responseid year *choices *date
	/// Rename/encode variables
	
	label define satisfaction_label 1 "Extremely dissatisfied" ///
		2 "Somewhat dissatisfied" 3 "Neither satisfied nor dissatisfied" ///
		4 "Somewhat satisfied" 5 "Extremely satisfied", replace
		
	encode q21 , gen(satisfaction) label(satisfaction_label)
	label var satisfaction "Overall satisfaction"

	ren q22 reason_unsatisfied
	
	replace q23 = subinstr(q23, "bad", "dissatisfied",1)
	replace q23 = subinstr(q23, "good", "satisfied",1)
	
	encode q23 , gen(satisfaction_information) label(satisfaction_label)
	label var satisfaction_information "Satisfaction information about process"

	encode q24, gen(visit_office)
	label var visit_office "Visit Office of Choice&Enrollment"

	ren q25_1 duration_visit
	label var duration_visit "Duration of office visit in minutes"

	encode q26 , gen(satisfaction_visit) label(satisfaction_label)
	label var satisfaction_visit "Satisfaction with visit to Office of Choice&Enrollment"

	ren q27 reason_unsatisfied_visit

	encode q32 , gen(expo)
	label var expo "Attend expo on school choice process"
	encode q33 , gen(expo_useful)
	label var expo_useful "Learn anything useful at expo"

	encode q34, gen(expo_reason_noattend)
	label var expo_reason_noattend "Reason for not attending any exposition by NHPS"
	encode q41, gen(catalogs)
	label var catalogs "Receive and use any catalogs on school choice process"

	encode q42, gen(catalogs_useful)
	label var catalogs_useful "Learn anything useful from catalogs"
	
	// 2019
	if `year' == 2019 {
		encode q43, gen(catalogs_usage)
		label var catalogs_usage "Usage of the printed catalogs"
		
		ren q44 catalogs_reason_no_use
		
		encode q51, gen(facebook_ads)
		label var facebook_ads "Saw Facebook Ads on School Choice Process"
		
		encode q52 , gen(facebook_remind)
		label var facebook_remind"Facebook Ads reminded to apply in time"
		
		encode q53, gen(facebook_useful)
		label var facebook_useful "Facebook Ad was useful"
		
		encode q61, gen(billboards)
		label var billboards "See any billboards about school choice process"

		encode q62, gen(billboards_remind)
		label var billboards_remind "Learn reminded to apply in time"
		
		encode q63, gen(billboards_useful)
		label var billboards_useful "Learn anything useful from billboards"
		
		encode q71, gen(prefer_more_choices_future)
		label var prefer_more_choices_future "Prefer to have more than 6 choices in the future"
		
		encode q73_1 , gen(feature_bus_route_info)
		label var feature_bus_route_info "New feature - information about priorities of app choices"

		encode q73_2 , gen(feature_priority_info)
		label var feature_priority_info "New feature - information about admission chances of app choices"

		encode q73_3 , gen(feature_ratex_info)
		label var feature_ratex_info "New feature - information about bus routes for app choices"

		encode q73_4 , gen(feature_suggestions)
		label var feature_suggestions "New feature - suggestions of potential schools"

		encode q73_5 , gen(feature_notifications)
		label var feature_notifications "New feature - frequent notificatons about important dates and information"

		encode q73_6 , gen(feature_earlier_outreach)
		label var feature_earlier_outreach "New feature - earlier outreach and information"
		
		encode q72, gen(satisfaction_bus_route_info) label(satisfaction_label)
		label var satisfaction_bus_route_info "Satisfaction with information on bus routes"

		encode q81, gen(MP1)
		label var MP1 "Rank MP school first on application"

		encode q82_1, gen(fav_schooltype)
		label var fav_schooltype "Favorite school type"

		encode q82_2, gen(fav_school)
		label var fav_school "Favorite school"

		ren q83_1 strategic_waste_choice
		label var strategic_waste_choice "hard to be admitted, and I did not want to waste a choice in my application"

		ren q83_2 strategic_increase_chances
		label var strategic_increase_chances "listing a different school first would raise my chances of being placed at that school"

		ren q83_3 strategic_hard
		label var strategic_hard "hard to be admitted, so I did not bother applying"			
		
		encode q93 , gen(oo_school_type)
		label var oo_school_type "Type of school of outside option"
		
		gen oo_private_NH = oo_school_type == 1
		gen oo_private_out = oo_school_type == 2
		gen oo_public_out = oo_school_type == 3
		label var oo_private_NH "Consider private schools in New Haven"
		label var oo_private_out "Consider private schools outside of New Haven"
		label var oo_public_out "Consider public schools outside of New Haven"
	}
	
	// 2020
	else {
		ren q43 catalogs_reason_no_use
		encode q51, gen(billboards)
		label var billboards "See any billboards about school choice process"

		encode q52, gen(billboards_useful)
		label var billboards_useful "Learn anything useful from billboards"
		
		encode q61, gen(prefer_more_choices_future)
		label var prefer_more_choices_future "Prefer to have more than 6 choices in the future"
				
		encode q62_1 , gen(feature_bus_route_info)
		label var feature_bus_route_info "New feature - information about priorities of app choices"

		encode q62_2 , gen(feature_priority_info)
		label var feature_priority_info "New feature - information about admission chances of app choices"

		encode q62_3 , gen(feature_ratex_info)
		label var feature_ratex_info "New feature - information about bus routes for app choices"

		encode q62_4 , gen(feature_suggestions)
		label var feature_suggestions "New feature - suggestions of potential schools"

		encode q62_5 , gen(feature_notifications)
		label var feature_notifications "New feature - frequent notificatons about important dates and information"

		encode q62_6 , gen(feature_earlier_outreach)
		label var feature_earlier_outreach "New feature - earlier outreach and information"
		
		encode q63, gen(satisfaction_bus_route_info) label(satisfaction_label)
		label var satisfaction_bus_route_info "Satisfaction with information on bus routes"

		encode q71, gen(MP1)
		label var MP1 "Rank MP school first on application"

		encode q72_1, gen(fav_schooltype)
		label var fav_schooltype "Favorite school type"

		encode q72_2, gen(fav_school)
		label var fav_school "Favorite school"

		ren q73_1 strategic_waste_choice
		label var strategic_waste_choice "hard to be admitted, and I did not want to waste a choice in my application"

		ren q73_2 strategic_increase_chances
		label var strategic_increase_chances "listing a different school first would raise my chances of being placed at that school"

		ren q73_3 strategic_hard
		label var strategic_hard "hard to be admitted, so I did not bother applying"	
		
		ren q81_1 surv_belief_r1 
		label var surv_belief_r1 "Admission chance belief at first ranked school"

		ren q82_1 surv_belief_unplaced 
		label var surv_belief_unplaced "Belief of not being placed at all"

		encode q83, gen(edit_app)
		label var edit_app "Edit application after initial submission"

		ren q84 reason_edit
		label var reason_edit "Reason to edit or revision application"
		
		encode q93_1 , gen(oo_private_NH)
		label var oo_private_NH "Consider private schools in New Haven"

		encode q93_2 , gen(oo_private_out)
		label var oo_private_out "Consider private schools outside of New Haven"

		encode q93_3 , gen(oo_public_out)
		label var oo_public_out "Consider public schools outside of New Haven"
		
	}

	// Both years
	encode q92, gen(consider_oo)
	label var consider_oo "Consider outside options such as private schools and public schools not in NHPS"

	ren q94 rank_fav_oo
	label var rank_fav_oo "Hypothetical rank of favorite OO school"

	encode q102, gen(omit_out_of_order)
	label var omit_out_of_order "Prefer non-listed NHPS schools more than some choices on application"

	encode q103_1, gen(not_waste_slot)
	label var not_waste_slot "Hard to be admitted to MP school and did not want to waste slot"

	encode q103_2 , gen(listMP_with_more_choices)
	label var listMP_with_more_choices "Would list MP school if had more choices"

	encode q103_3 , gen(impossible_MPplaced)
	label var impossible_MPplaced "almost impossible to be admitted to my favorite school, so I did not bother"

	encode q103_4 , gen(mistake)
	label var mistake "Made a mistake filling out the application"

	encode q104, gen(preferred_more_choices)
	label var preferred_more_choices "Would have preferred more than six choices"

	encode q112_1 , gen(no_oo_sure)
	label var no_oo_sure "No OO application because certain that kid will be placed at some NHPS school"

	encode q112_2 , gen(have_oo)
	label var have_oo "Have OO if unplaced"

	encode q112_3 , gen(continuation_option)
	label var continuation_option"Has continuation option at current school"

	encode q112_4 , gen(no_info_other_schools)
	label var no_info_other_schools "Don't know other schools well enough to apply"

	encode q112_5 , gen(belief_no_chance_other_schools)
	label var belief_no_chance_other_schools "Dont't think would get into any other schools'"

	drop q* 

	if `year' == 2019 {
		ren four_choices submit_full_app
		drop no_four_choices  
	}
	
	if `year' == 2020 {
		ren six_choices submit_full_app
	}
	label define submit_full_app_label 0 "No" 1 "Yes", replace
	label values submit_full_app submit_full_app_label
	
	tempfile data`year'
	save `data`year'', replace
}

clear
append using `data2019'
append using `data2020'

isid parentid year

save "$int/email_survey", replace